<include file="Public:header" />
<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Operation/js/my97date/wdatepicker.js"></script>
<div class="headbar">
    <div class="position"><span>商品</span><span>></span><span>二维码管理</span><span>></span><span>二维码列表</span></div>
    <div class="operating">
        <a href="{:U('Code/code_edit')}"><button class="operating_btn" type="button" ><span class="addition">生成二维码</span></button></a>
        <a href="javascript:void(0);"><button class="operating_btn" type="button" onclick="selectAll('id[]')"><span class="sel_all">全选</span></button></a>
        <a href="javascript:void(0);"><button class="operating_btn" type="button" onclick="code_del()"><span class="delete">删除</span></button></a>
        <a href="javascript:void(0);"><button class="operating_btn" type="button" onclick="codeSetting();" title="批量设置" alt="批量设置"><span class="remove">批量设置</span></button></a>
    </div>
</div>
<div class="searchbar">
    <form action="{:U('')}" method="get" name="searchListForm">
        <select class="auto" name="search[status]">
            <option value="">扫码状态</option>
            <option value="2">已扫码</option>
            <option value="1">未扫码</option>
        </select>
        <select class="auto" name="search[name]">
            <option value="go.name">商品名</option>
            <option value="c.goods_no">商品批次</option>
            <option value="c.code">序列号</option>
        </select>
        <input class="small" name="search[keywords]" type="text" value="" />
        <input type="hidden" name="search[create_time]" value="" />
        创建时间：<input class="small" type="text" id="create_time_start" onfocus="WdatePicker()" value="" />-
		<input class="small" type="text" id="create_time_end" onfocus="WdatePicker()" value="" />
        <!--分类数据显示-->
        <button class="btn" type="submit"  onclick='changeAction(false)'><span class="sel">筛 选</span></button>
        <button class="btn" onclick='changeAction(true)'><span class="sel">导出Excel</span></button>
    </form>
</div>

<form action="" method="post" name="orderForm">
    <div class="content">
        <table class="list_table">
            <colgroup>
                <col width="40px" />
                <col width="40px" />
                <col width="90px" />
                <col width="150px" />
                <col width="40px" />
                <col width="90px" />
                <col width="70px" />
                <col width="70px" />
                <col width="60px" />
                <col width="40px" />
                <col width="70px" />
                <col width="100px" />
                <col width="120px" />
                <col width="60px" />
            </colgroup>

            <thead>
                <tr>
                    <th>选择</th>
                    <th>ID</th>
                    <th>序列号</th>
                    <th>商品名称</th>
                    <th>商品批次</th>
                    <th>发货地</th>
                    <th>二维码</th>
                    <th>生成时间</th>
                    <th>扫码状态</th>
                    <th>扫码次数</th>
                    <th>扫码时间</th>
                    <th>访问IP</th>
                    <th>访问地址</th>
                    <th>操作</th>
                </tr>
            </thead>

            <tbody>
            <foreach name='codes' item='item'>
                <tr>
                    <td><input name="id[]" type="checkbox" value="{$item['id']}" /></td>
                    <td>{$item['id']}</td>
                    <td>{$item['code']}</td>
                    <td>{$item['name']}{$item['category']}</td>
                    <td>{$item['goods_no']}</td>
                    <td>{$item['area']}</td>
                    <td><a href="javascript:void(0);" onclick="get_code('{$item[code]}');" title="查看">查看</a></td>
                    <td>{$item.addtime|date="Y-m-d H:i:s",###}</td>
                    <td><if condition="$item['status'] eq 1">未扫码<else/>已扫码</if></td>
                    <td><if condition="$item['num'] gt 0"><a href="javascript:void(0);" onclick="code_num({$item['id']})" title="查看">{$item['num']}</a><else/>{$item['num']}</if></td>
                    <td><if condition="$item['time']">{$item.time}</if></td>
                    <td>{$item['ip']}<if condition="$item['country']">({$item.country})</if></td>
                    <td <if condition="($item['peg'] neq 1)">style="color: red;"</if>>{$item['add']}</td>
                    <td>
                    <if condition="$item['status'] eq 2"><a href="{:U('Code/reset',array('id'=> $item[id]))}" title="重置"><img class="operator" src="__PUBLIC__/Operation/images/admin/icon_refresh.gif" alt="重置" /></a></if>
                    <a href="javascript:void(0)" onclick="delModel({link:'{:U('Code/code_del',array('id'=> $item[id]))}'})" title="删除"><img class="operator" src="__PUBLIC__/Operation/images/admin/icon_del.gif" alt="删除" /></a>
                    </td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </div>
</form>
{$page}

<script type="text/javascript">
	//查看二维码图片
	function get_code(code){
	    var url = "{:U('Code/get_code',array('code'=> '@code@'))}";
	    url = url.replace('%40code%40',code?code:0);
	    art.dialog.open(url,{
	    	width:140,
	    	height:150,
	        id:'addSpecWin',
	        title:'二维码',
	    });
	}
    //DOM加载
    $(function(){
        var searchData = {$search};
        if(searchData){
            for(var index in searchData)
            {
                $('[name="search['+index+']"]').val(searchData[index]);
            }
        }
        $("#brand_id").blur(function(){
            var brand_id = $(this).val();
            $('input[name="search[brand_id]"]').val(brand_id);
        });
        initSearchbar();
    });
    
    // 初始化时间
    function initSearchbar()
    {
        var create_time = $('input[name="search[create_time]"]').val();
        if('' != create_time)
        {
            var create_time_arr = create_time.split(",");
            var len = create_time_arr.length;
            switch(len)
            {
                case 1:
                    $('#create_time_start').val(create_time_arr[0]);
                    break;
                case 2:
                    $('#create_time_start').val(create_time_arr[0]);
                    $('#create_time_end').val(create_time_arr[1]);
                    break;
            }
        }
    }
    
    //删除
    function code_del()
    {
        $("form[name='orderForm']").attr('action',"{:U('Code/code_del')}");
        confirm('确定要彻底删除所选中的信息吗？','formSubmit(\'orderForm\')');
    }
    //二维码导出或查询切换
    function changeAction(excel)
    {
        setCreatetimeVal();
        if(excel)
        {
            $("form[name=\"searchListForm\"]").attr("action", "{:U('Code/code_export')}");
            $("form[name=\"searchListForm\"]").attr("target", "_blank");
        }
        else
        {
            $("form[name=\"searchListForm\"]").attr("action", "{:U('Code/code_list')}");
            $("form[name=\"searchListForm\"]").attr("target", "_self");
        }
    }
    
    // 设置创建时间的值
    function setCreatetimeVal()
    {
        var create_time_start = $('#create_time_start').val();
        var create_time_end = $('#create_time_end').val();
        var create_time = '';
        if('' != create_time_start && '' != create_time_end)
        {
            var start_time = Date.parse(create_time_start);
            var end_time = Date.parse(create_time_end);
            if(start_time > end_time)
            {
                create_time = create_time_end + ',' + create_time_start;
            }
            else
            {
                create_time = create_time_start + ',' + create_time_end;
            }
        }
        else if ('' != create_time_start)
        {
            create_time = create_time_start;
        }
        else if ('' != create_time_end)
        {
            create_time = create_time_end;
        }
        $('input[name="search[create_time]"]').val(create_time);
        return true;
    }
    
     function code_num(id)
    {
        var url = "{:U('Code/code_num',array('id'=> '@id@'))}";
        url = url.replace('%40id%40',id?id:0);
        
        art.dialog.open(url,{
            id:'addSpecWin',
            title:'扫描记录',
            okVal:'确定',
            ok:function(iframeWin, topWin){
                var formObject = iframeWin.document.forms['specForm'];
                $.post(formObject.action,$(formObject).serialize(),function(json){
                    if(json.flag == 'success')
                    {
                        window.location.reload();
                        return true;
                    }
                    else
                    {
                        alert(json.message);
                        return false;
                    }
                },'json');
            }
        });
    }
</script>

<include file="Public:footer" />